<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<title></title>
<meta name="Generator" content="Cocoa HTML Writer">
<meta name="CocoaVersion" content="824.41">
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #9d1c12}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Helvetica; min-height: 22.0px}
p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Helvetica}
p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px}
p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; min-height: 12.0px}
p.p7 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco}
p.p8 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #bf0000}
p.p9 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #000000}
p.p10 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #000000; min-height: 12.0px}
span.s1 {color: #0026b4}
span.s2 {color: #9d1c12}
span.s3 {color: #000000}
span.s4 {color: #0000bf}
span.s5 {color: #007300}
span.Apple-tab-span {white-space:pre}
</style>
</head>
<body>
<p class="p1">//SLUGens released under the GNU GPL as extensions for SuperCollider 3, by Nick Collins, http://www.informatics.sussex.ac.uk/users/nc81/</p>
<p class="p2"><br></p>
<p class="p3"><b>WaveTerrain<span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>wave terrain synthesis</b></p>
<p class="p2"><br></p>
<p class="p4"><b>WaveTerrain.ar(bufnum=0, x, y, xsize=100, ysize=100, mul = 1.0, add = 0.0)</b></p>
<p class="p5"><br></p>
<p class="p4">Specify a surface <b>z(x,y)</b> via a buffer and scan it from the <b>x</b> and <b>y</b> inputs.<span class="Apple-converted-space"> </span></p>
<p class="p5"><br></p>
<p class="p4"><b>bufnum</b>- Your surface is a two dimensional array, but specified via a one dimensional buffer. The convention is exhibited below; note that you have to pass in the surface dimensions as well.<span class="Apple-converted-space"> </span></p>
<p class="p5"><br></p>
<p class="p4"><b>x,y</b>- audio rate scanning instructions. Both values must be in the range 0.0 to 1.0, or they are wrapped into this range.<span class="Apple-converted-space"> </span></p>
<p class="p6"><br></p>
<p class="p6"><br></p>
<p class="p1">//create buffer. I want the equation z = 2*(((x/100)**2) + ((abs(sin(10*y))/50)**(1/3)))-1</p>
<p class="p1">//over a 100 by 50 area</p>
<p class="p6"><br></p>
<p class="p1">//2d to 1d conversion follows index= y*rowlength+ x</p>
<p class="p7">(</p>
<p class="p7"><span class="s1">var</span> width= 100; <span class="s2">//= num cols</span></p>
<p class="p1"><span class="s1">var</span><span class="s3"> height=50; </span>//=num rows, though indexing bottom to top; i.e., standard Cartesian co-ordinates</p>
<p class="p6"><br></p>
<p class="p7">a=<span class="s1">Array</span>.fill(width*height,{<span class="s1">arg</span> i;<span class="Apple-converted-space"> </span></p>
<p class="p7"><span class="s1">var</span> xnow, ynow, x, y;<span class="Apple-converted-space"> </span></p>
<p class="p6"><br></p>
<p class="p7">xnow= i%width;</p>
<p class="p7">ynow= (i-xnow).div(width);</p>
<p class="p6"><br></p>
<p class="p7">x=xnow/width;</p>
<p class="p7">y=ynow/height;</p>
<p class="p6"><br></p>
<p class="p7">2*(((x)**2) + ((abs(sin(10*y)))**(1/3)))-1</p>
<p class="p6"><br></p>
<p class="p7">});</p>
<p class="p6"><br></p>
<p class="p6"><br></p>
<p class="p7">b=<span class="s1">Buffer</span>.sendCollection(s, a, 1);</p>
<p class="p7">)</p>
<p class="p6"><br></p>
<p class="p6"><br></p>
<p class="p1">//test scanning; you can't move fast enough... scan controls should also be audio rate!</p>
<p class="p7">{<span class="s1">WaveTerrain</span>.ar(b.bufnum,<span class="s1">MouseX</span>.kr(0.0,1.0), <span class="s1">MouseY</span>.kr(0.0,1.0),100,50)}.play</p>
<p class="p6"><br></p>
<p class="p6"><br></p>
<p class="p8">//LFNoise adds some drift to explore the landscape more</p>
<p class="p9">{<span class="s4">WaveTerrain</span>.ar(b.bufnum,<span class="s4">SinOsc</span>.ar(<span class="s4">MouseX</span>.kr(1,200,<span class="s5">'exponential'</span>)).abs + <span class="s4">LFNoise2</span>.ar(2),<span class="s4">SinOsc</span>.ar(<span class="s4">MouseY</span>.kr(1,300,<span class="s5">'exponential'</span>),pi*0.5).abs,100,50)}.play</p>
<p class="p10"><br></p>
<p class="p6"><br></p>
<p class="p6"><br></p>
<p class="p6"><br></p>
<p class="p6"><br></p>
<p class="p1">//change surface equation</p>
<p class="p7">(</p>
<p class="p7"><span class="s1">var</span> width= 100; <span class="s2">//= num cols</span></p>
<p class="p1"><span class="s1">var</span><span class="s3"> height=50; </span>//=num rows, though indexing bottom to top; i.e., standard Cartesian co-ordinates</p>
<p class="p6"><br></p>
<p class="p7">a=<span class="s1">Array</span>.fill(width*height,{<span class="s1">arg</span> i;<span class="Apple-converted-space"> </span></p>
<p class="p7"><span class="s1">var</span> xnow, ynow, x, y;<span class="Apple-converted-space"> </span></p>
<p class="p6"><br></p>
<p class="p7">xnow= i%width;</p>
<p class="p7">ynow= (i-xnow).div(width);</p>
<p class="p6"><br></p>
<p class="p7">x=xnow/width;</p>
<p class="p7">y=ynow/height;</p>
<p class="p6"><br></p>
<p class="p7">(((cos(5*x+1.7))**3) - ((abs(sin(23*y)))**(1/3)))</p>
<p class="p6"><br></p>
<p class="p7">});</p>
<p class="p6"><br></p>
<p class="p7">b.sendCollection(a);</p>
<p class="p7">)</p>
<p class="p6"><br></p>
<p class="p6"><br></p>
<p class="p6"><br></p>
<p class="p6"><br></p>
<p class="p6"><br></p>
<p class="p1">//change surface equation</p>
<p class="p7">(</p>
<p class="p7"><span class="s1">var</span> width= 100; <span class="s2">//= num cols</span></p>
<p class="p1"><span class="s1">var</span><span class="s3"> height=50; </span>//=num rows, though indexing bottom to top; i.e., standard Cartesian co-ordinates</p>
<p class="p6"><br></p>
<p class="p7">a=<span class="s1">Array</span>.fill(width*height,{<span class="s1">arg</span> i;<span class="Apple-converted-space"> </span></p>
<p class="p7"><span class="s1">var</span> xnow, ynow, x, y;<span class="Apple-converted-space"> </span></p>
<p class="p6"><br></p>
<p class="p7">xnow= i%width;</p>
<p class="p7">ynow= (i-xnow).div(width);</p>
<p class="p6"><br></p>
<p class="p7">x=xnow/width;</p>
<p class="p7">y=ynow/height;</p>
<p class="p6"><br></p>
<p class="p7">(((1.3*(cos(rrand(1,2)*x+1.7))**2) - ((abs(sin(rrand(1.2,4.9)*y)))**(1/2)))).max(-1.0).min(1.0)</p>
<p class="p6"><br></p>
<p class="p7">});</p>
<p class="p6"><br></p>
<p class="p7">b.sendCollection(a);</p>
<p class="p7">)</p>
<p class="p6"><br></p>
</body>
</html>
